package com.poizon.infrastructure.idem.core.exception;

import com.poizon.infrastructure.idem.core.domain.value.exception.IdempotentDbStoreException;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;

import java.util.HashMap;
import java.util.Map;

/**
 * spring统一异常处理
 */
@ControllerAdvice
public  class GlobalExceptionHandler extends ResponseEntityExceptionHandler {
    @ExceptionHandler(value = {IdempotentDbStoreException.class})
    protected ResponseEntity<Object> IdempotentDbStoreException(Exception ex) {
        Map<String, Object> body = new HashMap<>();
        return new ResponseEntity<>(body, HttpStatus.INTERNAL_SERVER_ERROR);
    }


}
